package main

import (
	"fmt"
)

func log(name, passwd string) bool {
	if name == "root" && passwd == "123456" {
		return true
	} else {
		return false
	}
}
func save(y *int, x int) {
	*y = *y + x
}

func spend(y *int, x int) {
	*y = *y - x
}

func main() {

	balance := 1000

	ptr := &balance
	var yourname string
	var yourpasswd string
	a := 0
	for i := 0; i < 3; i++ {
		fmt.Println("请输入你的用户名和密码")
		fmt.Scan(&yourname, &yourpasswd)
		logs := log(yourname, yourpasswd)
		if logs {
			fmt.Println("登录成功")
			break
		} else {
			fmt.Println("请重新输入")
		}
		a += 1
	}
	if a == 3 {
		fmt.Println("登录失败")
	} else {
		for {
			var choice int8
			var flag int

			fmt.Println("1.存钱")
			fmt.Println("2.取钱")
			fmt.Println("3.查询余额")
			fmt.Println("4.退出整个系统")
			fmt.Println("请选择你的选项")
			fmt.Scan(&choice)
			switch choice {
			case 1:
				c := 0
				fmt.Println("请输入你的存钱金额")
				fmt.Scan(&c)
				save(ptr, c)
				continue
			case 2:
				d := 0
				fmt.Println("请输入你的取钱金额")
				fmt.Scan(&d)
				if d > balance {
					fmt.Println("你的余额不足")
					continue
				} else {
					spend(ptr, d)
				}

				continue
			case 3:
				fmt.Println("你的余额还有：", balance)
				continue
			case 4:
				fmt.Println("你已经退出系统")
				flag = 0
				break
			}
			if flag == 0 {
				break
			}
		}
	}

}
